package lab03.test04;

import java.io.*;

public class Test04 {
    public static void main(String[] args) {
        String s = "";
        File myfile = new File("F:\\source");
        myfile.mkdirs();
        myfile = new File("F:\\target");
        myfile.mkdirs();        //利用file创建文件夹

        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream("F:\\source\\GALA - 追梦赤子心.mp3");
            byte[] data = new byte[fileInputStream.available()];

            while (fileInputStream.read(data) != -1) {
                s = new String(data);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }            //利用输出流写入文件

        FileOutputStream fileOutputStream = null;      //利用输入流读入文件
        try {
            fileOutputStream = new FileOutputStream("F:\\target\\GALA - 追梦赤子心.mp3");
            fileOutputStream.write(new String(s).getBytes());
            System.out.println("复制成功.");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
